package com.bye.util;

import java.util.HashMap;
import java.util.List;

public class Result extends HashMap<String, Object> {
    //无参构造, 当返回结果对象, 内置成功信息
    private Result() {
        //子类继承父类, 在子类中直接继承父类方法
        put("code", 200);
        put("msg", "success");
    }

    /*成功返回
     * */
    public static Result success() {
        return new Result();
    }


    //静态方法
    public static Result success(String msg) {
        Result result = new Result();
        result.put("msg", msg);
        return result;
    }

    /*
     * 异常返回
     * */
    public static Result error(String msg, int code) {
        Result result = new Result();
        result.put("code", code);
        result.put("msg", msg);
        return result;
    }

    public static Result error(String msg) {
        return error(msg, 500);
    }

    public static Result error() {
        return error("发现了异常, 请假查");
    }

    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
